package com.hxci.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hxci.dao.StudentMapper;
import com.hxci.pojo.student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

@Service
public class StudentService {

    @Autowired
    private StudentMapper studentMapper;

    public PageInfo<student> getStudentData(Map<String, Object> params, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<student> students = studentMapper.getStudentData(params);
        return new PageInfo<>(students);
    }

    public java.util.List<com.hxci.pojo.student> getStudentDataRaw(java.util.Map<String, Object> params) {
        return studentMapper.getStudentData(params);
    }

    public List<String> getAllClassNames() {
        return studentMapper.getAllClassNames();
    }

    public List<String> getAllTitles() {
        return studentMapper.getAllTitles();
    }

    public int getTotalStudentCount(Map<String, Object> params) {
        return studentMapper.getTotalStudentCountByCondition(params);
    }

    public int getTotalStudentCount() {
        return studentMapper.getTotalStudentCount();
    }

    public int updateScoreByNameAndTitle(String name, String title, String score) {
        java.util.HashMap<String, Object> params = new java.util.HashMap<>();
        params.put("name", name);
        params.put("title", title);
        params.put("score", score);
        return studentMapper.updateScoreByNameAndTitle(params);
    }

    public int updateScoreByNameAndTitle(String name, String title, String score, Integer wid) {
        java.util.HashMap<String, Object> params = new java.util.HashMap<>();
        params.put("name", name);
        params.put("title", title);
        params.put("score", score);
        if (wid != null) {
            params.put("wid", wid);
        }
        return studentMapper.updateScoreByNameAndTitle(params);
    }

    public java.util.List<com.hxci.pojo.student> getSubmissionsByName(String name){
        return studentMapper.getSubmissionsByName(name);
    }

    public java.util.List<java.util.Map<String,Object>> getClassSubmissionStats(java.util.Map<String,Object> params){
        return studentMapper.getClassSubmissionStats(params);
    }

    public java.util.List<com.hxci.pojo.student> getUnsubmittedStudents(java.util.Map<String,Object> params){
        return studentMapper.getUnsubmittedStudents(params);
    }

    public String getTitleByIndex(int index){
        if(index <= 0){
            return null;
        }
        return studentMapper.getTitleByOffset(index - 1);
    }

    public java.util.List<com.hxci.pojo.student> getSubmissionsByNameAndTitle(String name, String title){
        return studentMapper.getSubmissionsByNameAndTitle(name, title);
    }
}